home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / pctv3n2.zip / TIMERTST.C < prev    next >
C/C++ Source or Header  |  1992-04-16  |  2KB  |  64 lines

  1. /* TIMERTST.C
  2.  * Example program using RTCHDW functions.
  3.  *
  4.  * Sample MAKE file:
  5.  *
  6.  * .c.obj:
  7.  *    bcc -c $<
  8.  *
  9.  * timertst.exe: timertst.obj rtchdw.obj
  10.  *    bcc timertst.obj rtchdw.obj
  11.  */
  12. #include <stdio.h>
  13. #include <bios.h>
  14. #include "rtc.h"
  15.  
  16. static volatile unsigned long TickCount = 0;
  17. static volatile int SecCount = 0;
  18. static volatile unsigned int MinCount = 0;
  19. static volatile int Tick = 0;
  20.  
  21. /* Periodic ISR simply increments tick counter */
  22. void far MyPeriodicISR (void) {
  23.     TickCount++;
  24. }
  25.  
  26. /* Update ISR increments second count and
  27.  * sets the tick flag */
  28. void far MyUpdateISR (void) {
  29.     SecCount++;
  30.     Tick = 1;
  31. }
  32.  
  33. /* Alarm ISR increments minute count, clears second
  34.  * count and sets the tick flag. */
  35. void far MyAlarmISR (void) {
  36.     MinCount++;
  37.     SecCount = 0;
  38.     Tick = 1;
  39. }
  40.  
  41. /* Enable a 4.096 KHz timer, the update interrupt
  42.  * and a once-per-minute alarm ISR.
  43.  * Each second, display the elapsed time and the
  44.  * total number of timer ticks. */
  45. void main (void) {
  46.     struct RTCTIME Time = {0xff, 0xff, 0, 0};
  47.  
  48.     SetAlarmInt (&Time, MyAlarmISR);
  49.     SetUpdateInt (MyUpdateISR);
  50.     SetPeriodicInt (4, MyPeriodicISR);
  51.     EnableRTCint (PIE+UIE+AIE);
  52.     TimerOn ();
  53.     do {                               /* do until key pressed */
  54.         if (Tick) {
  55.             Tick = 0;
  56.             printf ("%02d:%02d  Tick count = %ld\n",
  57.                     MinCount, SecCount, TickCount);
  58.         }
  59.     } while (!bioskey (1));
  60.     TimerOff ();
  61.     ResetRTCint (PIE+UIE+AIE);
  62.     bioskey (0);                       /* read keyboard buffer */
  63. }
  64.